<?php

namespace App\Admin\Renderable;

use App\Models\SwtMerchant;
use Dcat\Admin\Grid;
use Dcat\Admin\Grid\LazyRenderable;

class MerchantRenderable extends LazyRenderable
{
    public function grid(): Grid
    {
        $ids = $this->ids ?? [];

        $id = $this->id ?? '';

        return Grid::make(new SwtMerchant(), function (Grid $grid) use ($ids, $id) {

            $grid->column('id');

            $grid->column('name') -> display(function ($value) {
                return $value ?? '-';
            });

            $grid->column('mobile','电话');


            $grid->column('status','状态') -> using(['禁用','启用'])->label(['danger','success']);


            $grid->quickSearch(['name']);

            $grid->paginate(5);

            $grid->disableRowSelector(false);

            $grid->rowSelector()->disable(function ($row) use ($ids, $id) {
                if($row->id == $id) {
                    return false;
                }
                return in_array($row->id, $ids);
            });

            $grid->disableActions();
        });
    }
}
